﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParsingProject
{
    public class LengthFixedParser : IParser
    {
        private IParser _innerParser;
        private int _lengthConstraint;
        private int _columnIndex;
        private bool _strictEqual;

        public LengthFixedParser(IParser parser, int lengthConst, 
            int columnIndex, bool shoulStrictEqual)
        {
            _innerParser = parser;
            _lengthConstraint = lengthConst;
            _columnIndex = columnIndex;
            _strictEqual = shoulStrictEqual;
        }

        public List<List<string>> Parse(string path)
        {
            var result = _innerParser.Parse(path);
            int columnCount = result[0].Count;

            result.RemoveAll(line => (_columnIndex >= line.Count) ||
                (_strictEqual ? 
                line[_columnIndex].Count() != _lengthConstraint :
                line[_columnIndex].Count() > _lengthConstraint));

            return result;
        }
    }
}
